package self.xine.basic.thread.entity;

/**
 * 多线程间共用的对象
 * @author xine
 * @date 2018年9月8日
 */
public class SharedObject {

	private int count = 10;
	private boolean isTerminated = false;
		
	public synchronized void add(int value) {
		if(value > 0) {
			count += value;
		}
	}
	
	public synchronized void sub(int value) {
		if(value > 0) {
			count -= value;
		}
	}
	
	public synchronized void set(int value) {
		if(value >= 0) {
			count = value;
		}
	}
	
	public synchronized int getCount() {
		return count;
	}

	public boolean isTerminated() {
		return isTerminated;
	}

	public void setTerminated(boolean isTerminated) {
		this.isTerminated = isTerminated;
	}
	
}
